#include <iostream>
#include <vector>
using namespace std;
const int N = 1e6 + 10;
using ll = long long;
ll r[N], c[N];
ll n, m;

int main()
{

    scanf("%d%d", &n, &m);

    std::vector<vector<ll>> a(n, vector<ll>(m));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            scanf("%lld", &a[i][j]);
            r[i] += a[i][j];
            c[j] += a[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {

            printf("%lld ", r[i] + c[j] - a[i][j]);
        }
        printf("\n");
    }
    return 0;
}